package com.example.wecomservice.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;

import java.util.concurrent.TimeUnit;

/**
 * @author Jamin
 * @Date 2023/2/3 12:07
 */
public class CacheManager {
    private static RedissonClient redissonClient = (RedissonClient) cn.hutool.extra.spring.SpringUtil.getBean("redissonClient");

    static Log log = LogFactory.getLog(CacheManager.class);

    public static void del(String key) {
        RBucket bucket = redissonClient.getBucket(key);
        bucket.delete();
    }

    public static void set(String key, Object value, int expiredTime) {
        RBucket bucket = redissonClient.getBucket(key);
        bucket.set(value, expiredTime, TimeUnit.SECONDS);
    }

    public static String get(String key) {
        RBucket bucket = redissonClient.getBucket(key);
        if (!bucket.isExists()) {
            return null;
        }
        return (String) bucket.get();
    }
}
